package Dao.impl;

import Dao.BaseDao;
import Dao.RainManageDao;
import entity.Rainquality;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class RainManageDaoImpl extends BaseDao implements RainManageDao {

    Rainquality rainquality;
    @Override
    public List<Rainquality> getAll() {
        String sql = "select * from rainquality";
        ResultSet rs = executeQuery(sql);
        List<Rainquality> list = new ArrayList<>();
        try {
            while (rs.next()) {
                rainquality = new Rainquality();
                rainquality.setId(rs.getInt("id"));
                rainquality.setDistrictName(rs.getString("districtName"));
                rainquality.setRain(rs.getInt("rain"));
                rainquality.setMonitoringStation(rs.getString("monitoringStation"));
                rainquality.setMonitoringAddress(rs.getString("monitoringAddress"));
                list.add(rainquality);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            closeAll(connection,pstmt,rs);
        }
        return list;
    }
}
